<script language="JavaScript">
  <!--
	$(document).ready(
	    function() {
	        //clicking the parent checkbox should check or uncheck all child checkboxes
	        $(".parent_checkbox").click(
	            function() {
	                $(this).parents('table:eq(0)').find('.child_checkbox').attr('checked', this.checked);
	                $(this).parents('table:eq(0)').find('.parent_checkbox').attr('checked', this.checked);
	            }
	        );
	        //clicking the last unchecked or checked checkbox should check or uncheck the parent checkbox
	        $('.child_checkbox').click(
	            function() {
	                if ($(this).parents('table:eq(0)').find('.parent_checkbox').attr('checked') == true && this.checked == false)
	                    $(this).parents('table:eq(0)').find('.parent_checkbox').attr('checked', false);
	                if (this.checked == true) {
	                    var flag = true;
	                    $(this).parents('table:eq(0)').find('.parent_checkbox').each(
		                    function() {
		                        if (this.checked == false)
		                            flag = false;
		                    }
	                    );
	                    $(this).parents('table:eq(0)').find('.parent_checkbox').attr('checked', flag);
	                }
	            }
	        );
	    }
	);
//-->
</script>
<div class="post_title">
			<h1>圖片搜索</h1>
		</div>
		<div class="post_body">
			<?php $this->load->view('admin/partials/notices') ?>
			<form action="<?php echo site_url('admin/galleries/search');?>" method="post">				
				<input type="text" name="keyword" value="<?php echo $keyword;?>" id="keyword" size="30"/>				
				<select name="type">
					<option value="id" <?php if('id' == $searchtype):?>selected="selected"<?php endif;?>>圖片ID</option>
					<option value="title" <?php if('title' == $searchtype):?>selected="selected"<?php endif;?>>圖片標題</option>
					<option value="description" <?php if('description' == $searchtype):?>selected="selected"<?php endif;?>>圖片描述</option>
					</select>
					<select name="category">
					<option value="0" <?php if('0' == $category_selected):?>selected="selected"<?php endif;?>>--請選擇圖片分類--</option>
					<?php foreach ($categories as $cagegory):?>
					<option value="<?php echo $cagegory->id;?>" <?php if($cagegory->id == $category_selected):?>selected="selected"<?php endif;?>><?php echo $cagegory->name;?></option>
					<?php endforeach;?>
					</select>				
					<input type="submit" name="submit" value="搜索" class="styled" />
				</form>				<br/>
				<br/>
				<form action="<?php echo site_url('admin/galleries/handle');?>" method="post">				
				<table class="admin">
				<tr>
					<th class="admin"><input type="checkbox" class="parent_checkbox" id="parentCheckBox" value="0"/></th>
					<th class="admin">圖片</th>
					<th class="admin">分類</th>
					<th class="admin">狀態</th>
					<th class="admin">發表日期</th>
					<th class="admin">操作</th>

				</tr>
				<?php if ($galleries): ?>
					<?php foreach ($galleries as $gallery): ?>
					<tr>
						<td class="admin"><input type="checkbox" class="child_checkbox" name="child_checkbox[]" value="<?php echo $gallery->id;?>"/></td>
						<td class="admin"><a href="<?php echo site_url('product/'. $gallery->id);?>" target="_blank"><img src="<?php echo gallery_url($gallery->path, 'small')?>"/></a><br /><?php echo mb_substr($gallery->title, 0 ,20);?></td>
						<td class="admin"><?php echo $gallery->name; ?></td>
						<td class="admin"><?php if($gallery->status == 'draft'): ?>未審核<?php else:?>審核<?php endif;?></td>
						<td class="admin"><?php echo $gallery->date_posted; ?></td>
						<td class="admin"><a href="<?php echo site_url('admin/galleries/edit_gallery/' . $gallery->id);?>"><img src="<?php echo image_url('admin/icons/edit.png');?>"/></a>&nbsp;<a href="<?php echo site_url('admin/galleries/delete_gallery/' . $gallery->id);?>" onclick="return confirm('你真的要刪除該圖片嗎?');"><img src="<?php echo image_url('admin/icons/delete.png');?>"/></a></td>
					</tr>
					<?php endforeach; ?>
					<?php endif;?>						
				<tr>
					<th class="admin"><input type="checkbox" class="parent_checkbox" value="0"/></th>

					<th class="admin" colspan="8"><select name="do">
<option value="0">--------</option>
<option value="delete">刪除</option>
<option value="draft">未審核</option>
<option value="published">審核</option>
</select><input type="submit" name="submit" value="設置" class="styled" /></th>
				</tr>
								</table>
				</form>				<br />
				<?php $this->load->view('admin/partials/pagination'); ?>

		</div>